<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>提前结算申请</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-header">
    
</div>
<div class="zz-list">
    <ul>
        <li>
            <span class="zz-left">可提前结算</span
            ><span class="zz-explain-icon zz-explain-icon-L"></span
        ><span class="zz-right zz-right-flr zz-advance-amt"></span>
        </li>
        <li>
            <span class="zz-left">本次提现金额</span
            ><input class="zz-code-num  zz-right-flr zz-advance-num" type="number" placeholder="请输入本次提现金额"/>
        </li>
        <li>
            <span class="zz-left">服务费</span
            ><span class="zz-right zz-right-flr zz-advance-service"></span>
        </li>
        <li>
            <span class="zz-left">到账银行卡</span
            ><span class="zz-right zz-right-flr zz-advance-bankCard"></span
        ><span class="zz-right zz-right-flr zz-advance-bankName"></span>
        </li>
    </ul>
</div>
<div class="zz-illustrate">
    <span></span>
</div>
<div class="zz-explain" style="display: none">
    <p class="zz-phone-explain">可提前结算金额说明</p>
    <div class="zz-bank-reserve">可提前结算金额由系统根据当日待结算金额计算得出</div>
    <span class="zz-know">确认</span>
</div>
<div class="zz-mask" style="display: none"></div>
<input class="footer" type="button" value="提交">
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript">

    var queryURLParameter = utils.queryURLParameter();
    var merId = queryURLParameter.merId;
    var data = '';
    var minAmount = '';
    var limitAmount = '';
    var bankAccount = '';
    var colAccName = '';
    var orderId = '';
    //初始化接口
    $.ajax({
        url: utils.ajaxUrl()+"h5/earlyPayController/earlyPayInitial",
        data: {
            merId: merId
        },
        async: false,
        type: 'get',
        success: function (res) {
            var res = JSON.parse(res);
			console.log(res);
            if (res && res.retCode == '0000') {
				limitAmount = res.limitAmount;
                minAmount = res.minAmount;
                orderId = res.orderId;

                data = res["EdrawInfReData"];
                bankAccount = data.bankAccount;
                colAccName = data.colAccName;

                $(".zz-advance-bankCard").html("(尾号" + utils.cutOut(bankAccount) + ")");
                $(".zz-advance-amt").html("￥" + limitAmount);
                $(".zz-advance-service").html(res.feeRate*100 + "%");
                $(".zz-header").html("截止" + res.currentTime + "统计");
                $(".zz-illustrate span").html("为确保资金及时到账，提前结算服务时间段为01:00-22:00点最低提现金额为" + minAmount + "元");
                $(".zz-advance-bankName").html(data.bankName);
            } else {
                utils.newModalPrompt(res.retMsg);
                $(".footer").attr("disabled", "true");
            }
        }
    });
</script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>

<script charset="utf-8" type="text/javascript">
	var amt = '';
	var feeamt = '';
	var flag = true;

    $footer.click(function () {
        var that = $(this);
        var amount = $(".zz-advance-num").val();
        //var val = $(".zz-advance-amt").html();
        //val = val.substring(1);
        //val = parseFloat(val);
		//console.log(amount);
        if(!utils.decimalPlaces(amount,that)){
            return false;
        }
        
        if (amount < parseFloat(minAmount.replace(",", ""))) {
            utils.newModalPrompt("最低提现金额为"+minAmount+"元，请您修改提现金额。",that);
            return false;
        }
        if (amount > parseFloat(limitAmount.replace(",", ""))) {
            utils.newModalPrompt("您输入的提现金额超出可提前结算的金额，请您修改提现金额。",that);
            return false;
        }
        

        $.ajax({
            url: utils.ajaxUrl()+"h5/serviceChargeController/queryPoundage",
            async: false,
            data: {
                merId: merId,
                amount: amount
            },
            type: 'get',
            success: function (res) {
            	var res = JSON.parse(res);
            	console.log(res);
                if (res && res.retCode == '0000') {
                	amt = res.amt;
                	feeamt = res.feeamt;
                } else {
                    utils.newModalPrompt(res.retMsg,that);
                    flag=false;
                }
            }
        });
        
        if(!flag){
        	return false;
        }
        
        $mask.show();
        
        new $.modal({
            title: '提示',//弹框title
            content: '本次提前结算将收取',//弹框内容
//            serviceCharge:"服务费￥100元，到账金额3433元",
            isshowclosebtn: true,//是否显示取消按钮
            showcontent: false,//false为弹出框组件二，true为弹出框组件一
            closecallback: function () {
                $mask.hide();
            },//点击关闭时触发事件
            surecallback: function () {
                //点击确定时触发事件
                utils.newModalAnimationShow("加载中");
				$("#btn-ensure").attr("disabled","true");
                $.ajax({
                    url: utils.ajaxUrl()+"h5/epayController/epay",
                    async: true,
                    data: {
                        merId: merId,
                        amount: amount,
                        bankAccount: bankAccount,
                        colAccName: colAccName,
                        orderId: orderId
                    },
                    type: 'get',
                    success: function (res) {
						var res = JSON.parse(res);
            			console.log(res);
                        $mask.hide();
                        if (res && res.retCode == '0000') {
                            utils.newModalAnimationHide();
                            if (res.state == 0) {
                                window.location.href = "../../html/h5/bankBindSuccess.html?settlementSuccess=success";
                            } else if (res.state == 1) {
                                window.location.href = "../../html/h5/settlementHandle.html?merId="+merId;
                            } else {
                                utils.newModalPrompt(res.retMsg,$footer);
                            }
                            $("#btn-ensure").removeAttr("disabled");
                        } else {
                            utils.newModalAnimationHide(0);
                            utils.newModalPrompt(res.retMsg,$footer);
                        }
                    }
                });
            }
        }).show();

        var str = '';
        str += '<div class="modal-body dzz-modal-body text-center zz-modal-body">服务费'
                + '<span class="zz-serviceCharge-color zz-feeamt-3">' + feeamt + '元</span>'
                + '，到账金额'
                + '<span class="zz-serviceCharge-color zz-amt-3">' + amt + '元</span>'
                + '</div>';
                
        $(".dzz-modal-body").after(str).css("color", "#666");
        $(".zz-modal-body").css({
            "color": "#666",
            "padding-top":".1rem"
        });
        $(".zz-serviceCharge-color").css("color", "#fe5e5e");

    })
</script>
</html>